package com.ziyun.erp.web.modules.craftConfig.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;

import io.renren.common.utils.UserUtil;
import io.renren.common.validator.ValidatorUtils;
import io.renren.modules.sys.entity.SysUserEntity;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.ziyun.erp.modules.craftConfig.entity.GoodsCraftConfigEntity;
import com.ziyun.erp.modules.craftConfig.service.GoodsCraftConfigService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 商品工艺配置
 *
 * @author zh
 * @email 296588519@qq.com
 * @date 2018-10-15 13:47:02
 */
@RestController
@RequestMapping("craftConfig/goodscraftconfig")
public class GoodsCraftConfigController {
    @Autowired
    private GoodsCraftConfigService goodsCraftConfigService;

    /**
     * 报价商品工艺配置 列表
     */
    @RequestMapping("/listQuote")
    @RequiresPermissions("craftConfig:goodscraftconfig:list")
    public R listQuote(@RequestBody Map<String, Object> params){
        PageUtils page = goodsCraftConfigService.queryQuotePage(params);
        return R.ok().put("page", page);
    }

    /**
     * 报价商品工艺配置 列表
     */
    @RequestMapping("/listStandard")
    @RequiresPermissions("craftConfig:goodscraftconfig:list")
    public R listStandard(@RequestBody Map<String, Object> params){
        PageUtils page = goodsCraftConfigService.queryStandardPage(params);
        return R.ok().put("page", page);
    }



    /**
     * 报价商品工艺配置 保存
     */
    @RequestMapping("/saveOrUpdate")
    @RequiresPermissions("craftConfig:goodscraftconfig:save")
    public R saveOrUpdate(@RequestBody GoodsCraftConfigEntity goodsCraftConfig){
        SysUserEntity sysUser =  UserUtil.getCurrentUser();
        if (goodsCraftConfig.getId() == null){
            goodsCraftConfig.setCreateDate(new Date());
            goodsCraftConfig.setCreateUser(sysUser.getUsername());

        }else {
            goodsCraftConfig.setUpdateDate(new Date());
            goodsCraftConfig.setUpdateUser(sysUser.getUsername());
        }
        goodsCraftConfigService.insertOrUpdate(goodsCraftConfig);
        return R.ok();
    }



}
